﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
@*<script>
    var keyValue = request('keyValue');
    $(function () {
        initControl();
    })
    function initControl() {
        if (!!keyValue) {

            $.SetForm({
                url: "../../PropertyManage/CS_Rectification/GetFormBillJson?keyValue=" + keyValue,
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    if (data.State =1) {
                        $('#IsState').val('1'); $('#IsState').attr('checked', 'checked');                       
                    }
                   else if (data.State = 2) {
                        $('#IsState').val('1'); $('#IsState').attr('checked', 'checked');
                        $('#IsCheck').val('1'); $('#IsCheck').attr('checked', 'checked');
                    }
                }
            });
        }
    }
</script>
<div style="margin-left: 10px; margin-top: 20px; margin-right: 30px;">
    <table class="form" style="border: 1px solid #BEBEBE; background-color: #f4f4f4;">
        <tr>
            <td class="formTitle">整改单号</td>
            <td class="formValue">
                <input id="Code" type="text" class="form-control" readonly="readonly" value="系统自动编号"></input>
            </td>
            <td class="formTitle">单据日期<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Date" type="text" class="form-control input-wdatepicker" placeholder="请输入单据日期" onfocus="WdatePicker()" />
            </td>
            <td class="formTitle">来源类别</td>
            <td class="formValue">
                <input id="SourceType" type="text" class="form-control" />
            </td>
            <td class="formTitle">来源编号</td>
            <td class="formValue">
                <input id="SourceId" type="text" class="form-control"  />
            </td>
        </tr>
        <tr>
            <td class="formTitle">商铺名称<font face="宋体">*</font></td>
            <td class="formValue" colspan="3">
                <div id="PSFullName" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
            </td>
            <td class="formTitle">经营业态</td>
            <td class="formValue">
                <input id="BCategopry" type="text" class="form-control"  />
            </td>
            <td class="formTitle">经营品牌</td>
            <td class="formValue">
                <input id="Brand" type="text" class="form-control"  />
            </td>
        </tr>
        <tr>
            <td class="formTitle">商户名称<font face="宋体">*</font></td>
            <td class="formValue" colspan="3">
                <input id="Cname" type="text" class="form-control" />
            </td>
            <td class="formTitle">商户联系人</td>
            <td class="formValue">
                <input id="CLname" type="text" class="form-control" />
            </td>
            <td class="formTitle">联系人电话</td>
            <td class="formValue">
                <input id="CLphone" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">施工单位</td>
            <td class="formValue" colspan="3">
                <input id="ConstructionUnit" type="text" class="form-control" />
            </td>
            <td class="formTitle">施工负责人</td>
            <td class="formValue">
                <input id="ConstructionManager" type="text" class="form-control" />
            </td>
            <td class="formTitle">负责人电话</td>
            <td class="formValue">
                <input id="CMLphone" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;line-height:50px;">
                整改内容
            </th>
            <td class="formValue" colspan="7">
                <textarea id="ContentDatail" class="form-control" style="height: 50px;"></textarea>
            </td>
        </tr>
    </table>
    <table class="form" style="border: 1px solid #BEBEBE; background-color: #f4f4f4; margin-top: 10px;">
        <tr>
            <td class="formTitle"></td>
            <td class="formValue"><input id="IsState" type="checkbox"  />是否完成</td>
            <td class="formTitle">实际完成日期</td>
            <td class="formValue" ><input id="StateDate" type="text" class="form-control input-wdatepicker" placeholder="请输入完成日期" onfocus="WdatePicker({ maxDate: '%y-%M-%d' })" /></td>
            <td class="formTitle"></td>
            <td class="formValue"></td>
            <td class="formTitle"></td>
            <td class="formValue"></td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;line-height:50px;">
                完成情况
            </th>
            <td class="formValue" colspan="7">
                <textarea id="StateMemo" class="form-control" style="height: 50px;"></textarea>
            </td>
        </tr>
    </table>
    <table class="form" style="border: 1px solid #BEBEBE; background-color: #f4f4f4;margin-top:10px;">
        <tr>
            <td class="formTitle"></td>
            <td class="formValue"><input id="IsCheck" type="checkbox"  />是否复验</td>
            <td class="formTitle">复验日期</td>
            <td class="formValue"><input id="CheckDate" type="text" class="form-control input-wdatepicker" placeholder="请输入完成日期" onfocus="WdatePicker({ maxDate: '%y-%M-%d' })" /></td>
            <td class="formTitle">复验人</td>
            <td class="formValue"><input id="CheckUserName" type="text" class="form-control" /></td>
            <td class="formTitle"></td>
            <td class="formValue"></td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;line-height:50px;">
                完成情况
            </th>
            <td class="formValue" colspan="7">
                <textarea id="CheckMemo" class="form-control" style="height: 50px;"></textarea>
            </td>
        </tr>
    </table>
    <div class="divRadius">
        创建人：张氏&nbsp;&nbsp;创建时间：2016-01-01 12：03&nbsp;&nbsp;最后修改人：李四&nbsp;&nbsp;修改时间：2016-12-6 12:21&nbsp;&nbsp;已审核&nbsp;&nbsp;审核人：王宇&nbsp;&nbsp;审核时间：2015-2-2 15:30
    </div>
</div>*@
<script>
    var keyValue = request('keyValue');
    var SourceId = request('SourceId');
    var PStruct = "@ViewBag.PStruct";
    var PStructId = "@ViewBag.PStructId";
    var Cname = "@ViewBag.Cname";
    var Ccode = "@ViewBag.Ccode";
    var ConstructionUnit = "@ViewBag.ConstructionUnit";
    var ConstructionManager = "@ViewBag.ConstructionManager";
    $(function () {
        initControl();
    });

    function initControl() {
        $("#PStruct").val(PStruct);
        $("#PStructId").val(PStructId);
        $("#Cname").val(Cname);
        $("#Ccode").val(Ccode);
        $("#ConstructionUnit").val(ConstructionUnit);
        $("#ConstructionManager").val(ConstructionManager);
        if (!!keyValue) {
            $.SetForm({
                url: "../../PropertyManage/CS_Rectification/GetFormBillJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    
                    $("#form1").SetWebControls(data);
                    switch (data.State) {
                        case 0: $(".CheckTr").remove();
                            $("#StateMemo1").attr("readonly", "readonly");
                            $("#State .dropdown-text").text("未完成");
                            break;
                        case 1:
                            if (data.CheckMark == 0) {
                                $(".CheckTr").remove();
                                $("#CheckFlag .dropdown-toggle").remove();
                                $("#CheckFlag .dropdown-menu").remove();
                                $("#State .dropdown-text").text("已完成");
                            }
                            else if (data.CheckFlag == null || data.CheckFlag == -1) { $("#State .dropdown-text").text("已完成待复验"); }
                            else { $("#State .dropdown-text").text("已完成复验"); }
                            break;
                        case 2: $("#State .dropdown-text").text("复验未通过"); $(".CheckTr").remove(); $(".Value2").remove(); break;
                        case 3: $("#State .dropdown-text").text("已完成复验");
                            $("#CheckFlag .dropdown-toggle").remove();
                            $("#CheckFlag .dropdown-menu").remove(); $("#CheckDate").attr("disabled", "disabled"); $("#CheckMemo").attr("readonly", "readonly"); break;
                        case 4: $(".CompleteTr").remove(); $("#State .dropdown-text").text("已取消");
                            $(".CheckTr").remove(); break;
                        default: break;

                    }
                    $("#Code").attr("readonly", "readonly");
                    $("#Date").attr("disabled", "disabled");
                    $("#ContentDetail").attr("readonly", "readonly");
                    $("#DateLimit").attr("disabled", "disabled");
                    $("#CheckMark").attr("disabled", "disabled");
                    $("#Memo").attr("readonly", "readonly");
                    if (data.State != 0 && data.State != 2) {
                        $("#State .dropdown-toggle").remove();
                        $("#State .dropdown-menu").remove();
                        $("#State .dropdown-text").css("width", "260px");
                        $("#StateDate").attr("disabled", "disabled");
                        $("#StateMemo1").attr("readonly", "readonly");
                        $("#StateMemo").attr("readonly", "readonly");
                    } else {  //完成状态选择
                        $("#State .dropdown-menu li").click(function () {
                            var text = $(this).find('a').html();
                            var value = $(this).find('a').attr('data-value');
                            $("#State .dropdown-text").html(text).attr('data-value', value);
                            if (value == 0) {
                                $("#StateMemo").val("新创建待完成");
                            } else if (value == 1) { $("#StateMemo").val("完成整改"); }
                            else { $("#StateMemo").val("已取消"); }
                        });
                    }
                    $("#StateMemo1").val(data.StateDate.substring(0, 10) + " " + data.CreateUserName + " " + data.StateMemo);
                    //if (data.State != 1 || data.CheckMark != 0) {
                    //    //完成状态选择
                    //    $("#State .dropdown-menu li").click(function () {
                    //        var text = $(this).find('a').html();
                    //        var value = $(this).find('a').attr('data-value');
                    //        $("#State .dropdown-text").html(text).attr('data-value', value);
                    //    });
                    //}
                    $("#State .dropdown-text").attr('data-value', data.State);
                    $("#CheckFlag .dropdown-text").attr('data-value', data.CheckFlag);
                    if (data.CheckFlag == null || data.CheckFlag == -1) {
                        $("#CheckFlag .dropdown-text").attr('data-value', "0");
                        $("#CheckDate").val("@DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")");
                        $("#CheckMemo").val("复验未通过");
                    }
                    if (data.CheckFlag == null || data.CheckFlag == 0 || data.CheckFlag == -1) {
                        $("#CheckFlag .dropdown-text").text("不通过");
                    } else {
                        $("#CheckFlag .dropdown-text").text("通过");
                    }
                    //复验状态选择
                    $("#CheckFlag .dropdown-menu li").click(function () {
                        var text = $(this).find('a').html();
                        var value = $(this).find('a').attr('data-value');
                        $("#CheckFlag .dropdown-text").html(text).attr('data-value', value);
                        if (value == 0) {
                            $("#CheckMemo").val("复验未通过");
                        } else if (value == 1) { $("#CheckMemo").val("完成复验"); }
                    });
                }
            });
        } else {
            $(".StateTr").remove();
            $(".CompleteTr").remove();
            $(".CheckTr").remove();
        }
    }


    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["SourceId"] = SourceId;
        postData["State"] = $("#State .dropdown-text").attr("data-value");
        postData["CheckFlag"] = $("#CheckFlag .dropdown-text").attr("data-value");
        $.SaveForm({
            url: "../../PropertyManage/CS_Rectification/SaveForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        });
    }
</script>
<div style="margin-left: 10px; margin-top: 20px; margin-right: 30px;">
    <table class="form" style="border: 1px solid #BEBEBE; background-color: #f4f4f4; margin-top: 5px;">
        <tr>
            <td class="formTitle" id="PSFullNameTD">商铺名称</td>
            <td class="formValue">
                <input id="PStruct" type="text" disabled class="form-control" />
            </td>
            <td class="formTitle">商铺编号</td>
            <td class="formValue">
                <input id="PStructId" disabled type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">商户名称</td>
            <td class="formValue">
                <input id="Cname" type="text" disabled class="form-control" />
            </td>
            <td class="formTitle">商户编号</td>
            <td class="formValue">
                <input id="Ccode" type="text" disabled class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">施工单位</td>
            <td class="formValue">
                <input id="ConstructionUnit" disabled type="text" class="form-control" />
            </td>
            <td class="formTitle">施工负责人</td>
            <td class="formValue">
                <input id="ConstructionManager" disabled type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">单据编号</td>
            <td class="formValue">
                <input id="Code" type="text" class="form-control" />
            </td>
            <td class="formTitle">单据日期</td>
            <td class="formValue">
                <input id="Date" type="text" class="form-control input-wdatepicker" value="@LeSoft.Util.Time.GetToday()" placeholder="请输入单据日期" onfocus="WdatePicker()" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">整改内容</td>
            <td class="formValue">
                <textarea id="ContentDetail" class="form-control" style="height: 30px;"></textarea>
            </td>
            <td class="formTitle">整改期限</td>
            <td class="formValue">
                <input id="DateLimit" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.AddDays(7).ToString("yyyy-MM-dd")" placeholder="请输入整改期限" onfocus="WdatePicker({ minDate: '#F{$dp.$D(\'Date\')}' })" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">选项</td>
            <td class="formValue" colspan="3">
                <div class="checkbox">
                    <label>
                        <input id="CheckMark" type="checkbox" checked="checked" />
                        是否需要复验
                    </label>
                </div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">备注</td>
            <td class="formValue" colspan="3">
                <textarea id="Memo" class="form-control" style="height: 50px;"></textarea>
            </td>
        </tr>
        <tr class="StateTr">
            <td class="formTitle">单据状态</td>
            <td class="formValue">
                <div id="State" class="btn-group">
                    <a class="btn btn-default dropdown-text" data-toggle="dropdown" data-value="0" style="width:230px;">未完成</a>
                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                    <ul class="dropdown-menu" style="width:230px;">
                        <li><a data-value="0" class="Value2">未完成</a></li>
                        <li><a data-value="1">已完成</a></li>
                        <li><a data-value="4" class="Value2">已取消</a></li>
                    </ul>
                </div>
            </td>
            <td class="formTitle">单据说明</td>
            <td class="formValue">
                <input id="StateMemo1" type="text" class="form-control" />
            </td>
        </tr>
    </table>
    <table class="form CompleteTr" style="border: 1px solid #BEBEBE; background-color: #f4f4f4; margin-top: 5px;">
        <tr>
            <td class="formTitle">完成时间</td>
            <td class="formValue">
                <input id="StateDate" type="text" class="form-control input-wdatepicker" value="@LeSoft.Util.Time.GetToday()" onfocus="WdatePicker()" />
            </td>
            <td class="formTitle">完成说明</td>
            <td class="formValue">
                <input id="StateMemo" type="text" class="form-control" />
            </td>
        </tr>
    </table>
    <table class="form CheckTr" style="border: 1px solid #BEBEBE; background-color: #f4f4f4;margin-top:5px;">
        <tr>
            <td class="formTitle">复验结果</td>
            <td class="formValue">
                <div id="CheckFlag" class="btn-group">
                    <a class="btn btn-default dropdown-text" data-toggle="dropdown" data-value="0" style="width:230px;">不通过</a>
                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                    <ul class="dropdown-menu" style="width:230px;">
                        <li><a data-value="0">不通过</a></li>
                        <li><a data-value="1">通过</a></li>
                    </ul>
                </div>
            </td>
            <td class="formTitle">复验时间</td>
            <td class="formValue">
                <input id="CheckDate" type="text" class="form-control input-wdatepicker" value="@LeSoft.Util.Time.GetToday()" onfocus="WdatePicker()" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">复验说明</td>
            <td class="formValue" colspan="3">
                <input id="CheckMemo" type="text" class="form-control" />
            </td>
        </tr>
    </table>
</div>


